/*
Merge Sorted Array
Given a sorted linked list, delete all duplicates such that each element appear only once.

Given two sorted integer arrays A and B, merge B into A as one sorted array.

Note:
You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from B. 
The number of elements initialized in A and B are m and n respectively.
*/

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <stack>
#include <fstream>
#include <sstream>
#include "print.h"
using namespace std;


void testForStack()
{
	stack<int> mystack;
	mystack.push(10);
	mystack.push(20);
	mystack.top() -= 5;
	cout << "mystack.top() is now " << mystack.top() << endl;
}

void testForIntToString()
{
	int a = 10;
	stringstream ss;
	ss << a;
	string str = ss.str();
	cout << str << endl;

	string str1 = to_string(a);

}



/**/
//Definition for singly-linked list.
struct ListNode {
	int val;
	ListNode *next;
	ListNode(int x) : val(x), next(NULL) {}
};

class Solution {
public:
	void merge(int A[], int m, int B[], int n) {

		int len = m + n-1;
		int aIndex = m - 1;
		int bIndex = n-1;
		while (0 <= aIndex && 0<=bIndex)
		{
			if (B[bIndex]>A[aIndex])
			{
				A[len--] = B[bIndex--];
			}
			else
			{
				A[len--] = A[aIndex--];

			}
		}

		while ( 0<= aIndex)
		{
			A[len--] = A[aIndex--];

		} 
		while (0 <= bIndex)
		{
			A[len--] = B[bIndex--];

		}
	}
};




int main(int argc, char* argv[])
{

	Solution s;

	
	for (int i = 1; i < argc; i++){

		ListNode *currtNode = new ListNode(0);
		cout << argv[i] << endl;

	}

	int A[] = { 1, 2, 3, 0, 0 };
	int B[] = { 2, 4 };
	//cout << << endl;
	s.merge(A, 3, B, 2);
	

	system("pause");
	return 0;
}